package com.dhl.fin.api.domain;

import com.dhl.fin.api.common.annotation.BusinessId;
import com.dhl.fin.api.common.annotation.Excel;
import com.dhl.fin.api.common.annotation.ExcelTitle;
import com.dhl.fin.api.common.domain.BasicDomain;
import com.dhl.fin.api.common.dto.OptionDto;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.List;


@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Excel("FINShare平台用户")
@Table(name = "t_account")
public class Account extends BasicDomain {

    @BusinessId
    @ExcelTitle(name = "uuid", code = "uuid")
    @Column(columnDefinition = "varchar(50)")
    private String uuid;

    @Column(columnDefinition = "varchar(50)")
    private String userNo;

    @ExcelTitle(name = "name", code = "name")
    @Column(columnDefinition = "varchar(50) ")
    private String name;

    @Column(columnDefinition = "varchar(50) ")
    private String email;

    @Column(columnDefinition = "bit default 1 ")
    private Boolean available = true;

    @Column(columnDefinition = "bit default 0 ")
    private Boolean isSuperManager = false;


    public Account() {
    }


    public Account(Long id) {
        this.id = id;
    }


    /**
     * 一个项目下有多少用户
     */
    @ManyToMany
    @JoinTable(name = "t_account_project",
            joinColumns = {@JoinColumn(name = "account_id")},
            inverseJoinColumns = {@JoinColumn(name = "project_id")})
    private List<Project> projects;

    @ManyToMany
    @JoinTable(name = "t_account_role",
            joinColumns = {@JoinColumn(name = "account_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private List<Role> roles;

    @ManyToMany
    @JoinTable(name = "t_account_dataper_tree",
            joinColumns = {@JoinColumn(name = "account_id")},
            inverseJoinColumns = {@JoinColumn(name = "tree_id")})
    private List<Tree> dataPerTrees;


    @Transient
    private List<OptionDto> roleOptions;

    @Transient
    private List<OptionDto> projectOptions;

    @Transient
    private List<String> roleId;

    @Transient
    private List<Long> userIds;

    @Transient
    private List<Long> dataPerTreeIds;

    @Transient
    private String manageProjectStr;

    @Transient
    private String roleStr;

    @Transient
    private List<String> manageProjectIds;

}

